<template>
  <div id="student">
    <el-row class="padding-50">
      <el-col :span="24">
        <ul class="list">
          <li class="logo">
            <i class="iconfont icon-kaoshi"></i>
            <span>DORO-Learning-Online</span>
          </li>
          <li><router-link :to="`/student/learn/${courseId}`">章节学习</router-link></li>
          <li><router-link :to="`/student/learn_document/${courseId}`">课程资料</router-link></li>
          <li class="logo"><router-link :to="`/student/learn_info/${courseId}`">课程信息</router-link></li>
          <li><router-link :to="`/student/AIhelper/${courseId}`">智能学习助手</router-link></li>
          <li><router-link to="/student/message">我的消息</router-link></li>
          <li><router-link to="/student">返回首页</router-link></li>
          <li class="right" @mouseenter="flag = true" @mouseleave="flag = false">
            <a href="javascript:;">
              <i class="iconfont icon-Userselect icon"></i>{{ user.userName }}
            </a>
            <div class="msg" v-if="flag">
              <p @click="manage">管理中心</p>
              <p class="exit" @click="exit">退出</p>
            </div>
          </li>
        </ul>
      </el-col>
    </el-row>

    <div class="main">
  <div class="course-card-horizontal">
    <h2 class="title">{{ courseInfo.courseName }}</h2>
    <div class="info-row">
      <div class="left-box">
        <p class="label">授课老师：</p>
        <p class="teacher">{{ courseInfo.teacherName }}</p>
        <p class="label">教师编号：</p>
        <p class="teacher">{{ courseInfo.teacherID }}</p>
      </div>
      <div class="right-box">
        <p class="label">课程简介：</p>
        <div class="desc-box">{{ courseInfo.description }}</div>
      </div>
      
    </div>
  </div>


  </div>
    <router-view></router-view>
    <v-footer></v-footer>
  </div>
</template>

<script>
import myFooter from '@/components/student/myFooter'
import { mapState } from 'vuex'

export default {
  components: {
    'v-footer': myFooter
  },
  data() {
    return {
      flag: false,
      user: {},
      courseId: null,
      courseInfo: {}
    }
  },
  created() {
    this.userInfo()
    this.courseId = this.$route.params.courseId
    // 等 userInfo 赋值完再调用
  this.$nextTick(() => {
    this.loadCourseInfo()
  })
  },
  methods: {
    userInfo() {
      const name = this.$cookies.get('cname')
      const id = this.$cookies.get('cid')
      this.user = { userName: name, studentId: id }
    },
    exit() {
      this.$cookies.remove('cname')
      this.$cookies.remove('cid')
      this.$router.push('/')
    },
    manage() {
      this.$router.push('/student/manager')
    },
    loadCourseInfo() {
      const studentId = this.user.studentId
      this.$axios.get('/api/course/studentid', {
      params: { studentID: studentId }
      }).then(res => {
        if (res.data && Array.isArray(res.data)) {
          const course = res.data.find(c => c.id == this.courseId)
          if (course) {
            this.courseInfo = course
          } else {
            this.$message.error('未找到该课程')
          }
        } else {
          this.$message.error('课程信息加载失败')
        }
      }).catch(() => {
      this.$message.error('请求失败')
      })
    }
  },
  computed: mapState(['isPractice'])
}
</script>

<style scoped>
.right .icon {
  margin-right: 6px;
}
#student .padding-50 {
  margin: 0 auto;
  padding: 0 50px;
  box-shadow: 0 0 10px 4px rgba(1, 149, 255, 0.1);
  background-color: #fff;
}
.list a {
  text-decoration: none;
  color: #334046;
}
li {
  list-style: none;
  height: 60px;
  line-height: 60px;
}
#student .list {
  display: flex;
}
#student .list li {
  padding: 0 20px;
  cursor: pointer;
}
#student .list li:hover {
  background-color: #0195ff;
  transition: all 0.3s ease;
}
#student .list li:hover a {
  color: #fff;
}
#student .list .right {
  margin-left: auto;
  position: relative;
}
#student .list li.right:hover a {
  color: #000;
}
#student .list .logo {
  display: flex;
  font-weight: bold;
  color: #2f6c9f;
}
#student .list .logo i {
  font-size: 50px;
}
.right .msg {
  text-align: center;
  position: absolute;
  top: 60px;
  left: 0;
  display: flex;
  flex-direction: column;
  border-radius: 2px;
  border-bottom: 3px solid #0195ff;
  background-color: #fff;
}
.right .msg p {
  height: 40px;
  line-height: 40px;
  width: 105px;
}
.right .msg p:hover {
  background-color: #0195ff;
}
.course-card-horizontal {
  background: #ffffff;
  border-radius: 12px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
  padding: 30px;
  margin: 30px auto;
  max-width: 900px;
  border-left: 6px solid #0195ff;
  animation: fadeInUp 0.5s ease;
}

.course-card-horizontal .title {
  font-size: 26px;
  font-weight: bold;
  color: #2f6c9f;
  margin-bottom: 24px;
  border-bottom: 1px solid #eee;
  padding-bottom: 10px;
}

.info-row {
  display: flex;
  gap: 40px;
}

.left-box, .right-box {
  flex: 1;
}

.label {
  font-size: 16px;
  font-weight: bold;
  margin-bottom: 8px;
  color: #333;
}

.teacher {
  font-size: 16px;
  color: #444;
  background: #f2f8ff;
  padding: 10px 16px;
  border-left: 4px solid #0195ff;
  border-radius: 6px;
}

.desc-box {
  font-size: 15px;
  line-height: 1.6;
  padding: 12px 18px;
  background-color: #f9f9f9;
  border-left: 4px solid #0195ff;
  border-radius: 6px;
  color: #555;
  min-height: 80px;
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
.teacher-id {
  font-size: 14px;
  color: #888;
  margin-top: 8px;
  padding-left: 10px;
}
</style>
